<?php
$isReloadable = false;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');

$sql_sel = "SELECT m.cod_modulo, m.descr as m_descr , p.* "
		." FROM wfm_pagine p " 
		." LEFT JOIN wfm_moduli m ON p.id_modulo = m.id_modulo "
		." WHERE p.id_pagina = ".reqVarInt('id');
$objDB->query($sql_sel,'selRec');
if(!$aRow = $objDB->fetch('selRec')) {
	backOnErr("id. errato");
}
	
reqDef('cod_pagina',$aRow['cod_pagina']);
reqDef('descr',$aRow['descr']);
reqDef('tipo',$aRow['tipo']);
reqDef('tipo_inst',$aRow['tipo_inst']);
reqDef('script',$aRow['script']);
reqDef('idm',$aRow['id_modulo']);


if (reqVar('azione') == 'salva') {
	$msgPag = conferma();
} 


$sCmdR = "";
$sCmdR .= "<a class=\"cmd1\" href=\"javascript:document.frm1.submit();\" >salva</a>";
$sCmdR .= cmdTorna('torna');

$sHtmlMod = "<table class=\"tab1\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" align='center'>\n";
$sHtmlMod .= getHtmlRigaRif();
$sHtmlMod .= "<tr>\n";
$sHtmlMod .= "<td class='lab1' colspan='3'>Modulo</td>\n";
$sHtmlMod .= "<td class='txt1' colspan='3'>".$aRow['cod_modulo']."</td>\n";
$sHtmlMod .= "<td class='txt1' colspan='14'>".$aRow['m_descr']."</td>\n";
$sHtmlMod .= "</tr>\n";
$sHtmlMod .= "</table>";

$aOpz['sottotit'] = $sHtmlMod;

testaHtml('Gestione work-flow','Modifica pagina',$msgPag,'gest',$aOpz);
?>
<script language="JavaScript" type="text/javascript">
function apriPopUpInsReg(campo,tr){
  	url = "regInsPopUp.php?id=<?=reqvar('idm');?>&tr="+tr+"&campo="+campo+"&xsn=<?=XSN?>";
	window.open(url, 'nuovaPag','width=730,height=300,top=50,left=50,resizable=yes,scrollbars=yes');
}
</script>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right">
			<? echo $sCmdR; ?>
      </td>
   </tr>
</table>
<?=getHtmlForm('frm1','',array('enctype'=>true));?>
<?=getHtmlHidden('azione','salva');?>
<?=getHtmlHidden('id');?>
<?=getHtmlHidden('xsn',XSN);?>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif();?>
   <tr>
      <td class="tit1" colspan='20' align='center'>Script Pagina</td>
   </tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Codice</td>
      <td class="txt1" colspan='3' align='left'>
      	<?php  echo getHtmlVisCode('cod_pagina')?>
		</td>
      <td class="txt1" colspan='8' align='left'>
      	<?php  echo getHtmlVisText('descr')?>
		</td>
      <td class="lab1" colspan='1' align='left'>Tipo</td>
      <td class="txt1" colspan='5' align='left'>
      	<?php  echo getHtmlVisText('tipo')."/".getHtmlVisText('tipo_inst')?>
		</td>
   </tr>
   <tr>
      <td class="lab1" colspan='20' align='center'>Script</td>
   </tr>
   <tr>
      <td class="txt1" colspan='20' align='center'>
		<?php 
		$aOptScr = array("style"=>"font-family:courier;");
		echo getHtmlTextArea('script',100,20,'@REQ',$aOptScr);
		?>
		</td>
   </tr>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right">
			<? echo $sCmdR; ?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();
function conferma() {
	global $objDB;
	$msg = '';

	if ($msg != '') {
		return $msg;
	}
	$sSql = "UPDATE wfm_pagine SET script = '".reqVarAS('script')."'"
		." WHERE id_pagina = ".reqVarInt('id');
	$objDB->exec($sSql,'updRec');
	//dbg_($sSql);
	header("Location: ".urlTorna(_t("script modificato")));
	exit();
}
